package cn.bdqn.web.shiro;

import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.util.Factory;
import org.junit.Test;
import org.apache.shiro.mgt.SecurityManager;

import cn.app.utils.MD5Utils;

public class CustomRealm extends AuthorizingRealm{

	
	@Override
	public String getName() {
		
		return "CustomRealm";
	}
	
	
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(
			AuthenticationToken token) throws AuthenticationException {

		System.out.println("开始认证！");
		//获得用户名
		String username =(String) token.getPrincipal(); 
		
		//service
		if(!"admin".equals(username)){
			//用户名错误
			return null;
			
		}
		String password="1234";
		
		//if(密码一致)
		/*Session session=SecurityUtils.getSubject().getSession();
		session.setAttribute("devUser", );*/
		
		return new SimpleAuthenticationInfo(username, password,getName());
	}
	
	
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) {
		// TODO Auto-generated method stub
		return null;
	}


	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
